import java.util.*;

class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class Text {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        List<List<Integer>> list = new LinkedList<>();
        if(root==null){
//            return list;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()){
            List<Integer> list1 = new ArrayList<>();
            int count = queue.size();
            for (int i = 0; i < count; i++) {
                TreeNode node = queue.poll();
                list1.add(node.val);
                if(node.left!=null){
                    queue.add(node.left);
                }
                if(node.right!=null){
                    queue.add(node.right);
                }
            }
            list.add(list1);
        }
        int count2 = list.size();
        List<List<Integer>> lists = new ArrayList<>();
        for (int i = count2; i >=0 ; i--) {
            lists.add(list.get(i));
        }
    }
}
